class BannerWebpackPlugin{
    constructor(options) {
        this.options = options;
    }
    apply(compile){
        compile.hooks.emit.tapAsync("BannerWebpackPlugin",(compilation,callback)=>{

            // 得到将要输出的文件，只获取JS和CSS
            const assetPaths = Object.keys(compilation.assets).filter(assetsFile=>{
                let extensions  = ["js","css"]
                let splits = assetsFile.split(".")
                let splitEd = splits[splits.length - 1]
                return extensions.includes(splitEd)
            })

            debugger

            assetPaths.forEach(path=>{
                // 得到文件本身
                const asset = compilation.assets[path]
// 要添加的注释信息
const newSource = `/**
 * author：${this.options.auther}
 */
 ${asset.source()}
`
                // 覆盖资源
                compilation.assets[path] = {
                    // 返回新的资源
                    source(){
                        return newSource
                    },
                    // 返回新的大小
                    size(){
                        return newSource.length
                    }
                }
            })
            callback()
        })
    }
}

module.exports = BannerWebpackPlugin
